package middleware

import (
	"github.com/gin-gonic/gin"
	"go-caipu/pkg/setting"
	"gorm.io/gorm/utils"
)

var IgnorePath = []string{
	"/api/admin/logout",
	"/api/auth/login",
	"api/captcha/behavior",
}

// DemoEvnHandler system demo mode
func DemoEvnHandler(cfg *setting.Cfg) gin.HandlerFunc {
	return func(c *gin.Context) {
		method := c.Request.Method
		if cfg.Application.Mode != "demo" {
			c.Next()
			return
		}
		if method == "GET" || method == "OPTIONS" || utils.Contains(IgnorePath, c.Request.RequestURI) {
			c.Next()
			return
		}
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "谢谢您的参与，当前仅做演示使用不支持操作！\U0001F600\U0001F600\U0001F600",
		})
		c.Abort()
		return
	}
}
